package register;

import com.xiguanlezz.cn.api.common.Constants;
import com.xiguanlezz.cn.api.naming.pojo.ServiceInfo;
import com.xiguanlezz.cn.client.naming.NacosNamingService;
import org.junit.Assert;
import org.junit.Test;

import java.util.Objects;
import java.util.Properties;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/27 13:28
 * @Description：
 */
public class _5_服务订阅 {

    private static final String INSTANCE_SERVICE_NAME = "testRegisterInstance";
    private static final String INSTANCE_IP = "127.0.0.1";
    private static final int INSTANCE_PORT = 10086;
    private static final String INSTANCE_CLUSTER_NAME = "cluster1";


    @Test
    public void subscribeInstance() throws Exception {
        Properties properties = new Properties();
        properties.setProperty("serverAddr", "127.0.0.1:8848");
        NacosNamingService nacosNamingService = new NacosNamingService(properties);
        nacosNamingService.registerInstance(INSTANCE_SERVICE_NAME, INSTANCE_IP, INSTANCE_PORT);
        ServiceInfo serviceInfo = nacosNamingService.subscribe(INSTANCE_SERVICE_NAME, Constants.DEFAULT_GROUP, INSTANCE_CLUSTER_NAME);
        Assert.assertTrue(Objects.nonNull(serviceInfo));
        Assert.assertEquals(INSTANCE_SERVICE_NAME, serviceInfo.getName());
        Assert.assertEquals(INSTANCE_CLUSTER_NAME, serviceInfo.getClusters());
        Assert.assertEquals(Constants.DEFAULT_GROUP, serviceInfo.getGroupName());
    }
}
